package com.ecric.sensor;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.view.View;

/**
 *
 * 自定义水平仪控件
 * <h3>Description</h3>
 * TODO
 * <h3>Author</h3> Eric
 * <h3>Date</h3> 2017/10/18 14:03
 * <h3>Copyright</h3> Copyright (c)2017 Shenzhen TLKY  Co., Ltd. Inc. All rights reserved.
 */
public class GradienterView extends View{

    /** 定义 水平仪 仪表盘图片*/
    public Bitmap back;
    /** 定义 水平仪 气泡图片*/
    public Bitmap bubble;
    /** 定义水平仪中 气泡的X、Y 坐标*/
    public int bubbleX,bubbleY;

    public GradienterView(Context context) {
        super(context);
    }

    public GradienterView(Context context, AttributeSet attrs) {
        this(context,attrs,0);
    }

    public GradienterView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init() {
        back = BitmapFactory.decodeResource(getResources(),R.mipmap.icon_g);
        bubble = BitmapFactory.decodeResource(getResources(),R.mipmap.icon_bubble);
    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(back,0,0,null);
        canvas.drawBitmap(bubble,bubbleX,bubbleY,null);
    }
}
